function [media_cortes]=paralelismo_gramatico(xbin,ubl,dbla)
warning off all
[m,n]=size(xbin);
s=1;
rectas=[];
centro=ubl+round((dbla-ubl)/2);
while (s<=n)&& (isempty(find((xbin(centro,[s:n]))==0))==0)
    if xbin(centro,s)==0
        x1=s;
        while xbin(centro,s)==0      
                    s=s+1;
        end
        
        %buscamos los extremos%
        %extremo superior%
        x11=x1;
        tt=centro-1;
        while (isempty(find((xbin(tt,[x11-2:x11+2]))==0))==0)
            x11=x11+(min(find((xbin(tt,[x11-2:x11+2]))==0))-3);
            tt=tt-1;
        end  
        tt=tt+1;
        x22=x11;
        while xbin(tt,x22)==0      
                    x22=x22+1;
        end
        x22=x22-1; 
        c=sum([x11:x22])/length([x11:x22]);  %%% columna  c  fila  tt
        
        if isempty(find(rectas(2:2:end)==c))
        
            rectas=[rectas tt];
            rectas=[rectas c];
        
            %extremo inferior%
            x11=x1;
            tt=centro+1;
            while (isempty(find((xbin(tt,[x11-2:x11+2]))==0))==0)
                x11=x11+(min(find((xbin(tt,[x11-2:x11+2]))==0))-3);
                tt=tt+1;
            end  
            tt=tt-1;
            x22=x11;
            while xbin(tt,x22)==0      
                    x22=x22+1;
            end
            x22=x22-1; 
            c=sum([x11:x22])/length([x11:x22]);  %%% columna  c  fila  tt
        
            rectas=[rectas tt];
            rectas=[rectas c];
       end     
         
       else
            s=s+1;
       end
   
end

%buscamos los puntos de corte de las rectas%
cortes=[];cortes2=[];
for s=1:4:length(rectas)-8
    wx=[];wy=wx;
    m1=(rectas(s+2)-rectas(s))/(rectas(s+3)-rectas(s+1));
    m2=(rectas(s+6)-rectas(s+4))/(rectas(s+7)-rectas(s+5));
    ecuacion=strcat(num2str(m1),'*x-((',num2str(m1),'*',num2str(rectas(s+1)),')-',num2str(rectas(s)),')=',num2str(m2),'*x-((',num2str(m2),'*',num2str(rectas(s+5)),')-',num2str(rectas(s+4)),')');
    wx=solve(ecuacion);    
    wy= (m1*wx)-(m1*rectas(s+1)-rectas(s));
    x=inf;
    wx=subs(wx,x);
    if ((isempty(wx)==0)&&(vpa(wx)~='(NaN)')&&(double(wx)~=inf)&&(double(wx)~=-inf))
        cortes=[cortes wy wx];
        cortes2=[cortes2 rectas(s+2) rectas(s+3) wy wx rectas(s+6) rectas(s+7) wy wx];
        
    end
end
if isempty(cortes)==0
    lineas=double(cortes);
    d=[];
    for s=1:2:length(lineas)
        d=[d (centro-lineas(s))];
    end
else
    d=0;
end
media_cortes=mean(d);
%representacion%
clear lineas;
lineas=double(cortes2);
imshow(xbin);
hold on
for s=1:4:length(lineas)
    line([lineas(s+1), lineas(s+3)],[lineas(s), lineas(s+2)],'Color','r','LineWidth',3);
    plot(lineas(s+3),lineas(s+2),'bo');
end

hold off